#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
typedef struct IM
{
    char name[10];
    int id;
    char degree;
    int score;
    int dscorre;

}ds;
void SWAP(ds arr[5],int idc[5])
{
    int i = 0;
    int j = 0;
    int ct = 0;
    for (i; i < 4; i++)
    {
        int a = 0;
        int b = 0;
        for (j = 0; j < 4 - i; j++)
        {
            for (ct = 0; ct < 5; ct++)
            {
                if (idc[j] == arr[ct].id)
                    a = arr[ct].dscorre;
                if (idc[j + 1] == arr[ct].id)
                    b = arr[ct].dscorre;
            }
            if (a > b)
            {
                    int tmp = idc[j];
                    idc[j] = idc[j + 1];
                    idc[j + 1] = tmp;
                
            }
        }
    }
}
int main()
{
    ds arr[5];
    int i = 0;
    int idc[5] = { 0 };
    for (i; i < 5; i++)
    {
        scanf("%s", arr[i].name);
        scanf("%d", &arr[i].id);
        scanf(" %c", &arr[i].degree);
        scanf("%d", &arr[i].score);
    }
    for (i = 0; i < 5; i++)
    {
        idc[i] = arr[i].id;
    }
    for (i = 0; i < 5; i++)
    {
        printf("%s", arr[i].name);
        printf(" %d", arr[i].id);
        printf(" %c", arr[i].degree);
        printf(" %d", arr[i].score);
        printf("\n");
    }
    printf("\n");
    for (i = 0; i < 5; i++)
    {
       
        if (arr[i].degree == 'A')
            arr[i].dscorre = (arr[i].score + 90) / 2;
        else if(arr[i].degree=='B')
            arr[i].dscorre = (arr[i].score + 80) / 2;
        else if(arr[i].degree =='C')
            arr[i].dscorre = (arr[i].score + 70) / 2;
        else
            arr[i].dscorre = (arr[i].score + 60) / 2;

    }
    SWAP(arr,idc);
    int cd = 0;
    for (i = 0; i < 5; i++)
    {
        for (cd = 0; cd < 5; cd++)
        {
            if (idc[i] == arr[cd].id)
            {
                printf("%s", arr[cd].name);
                printf(" %d", arr[cd].id);
                printf(" %c", arr[cd].degree);
                printf(" %d", arr[cd].score);
                printf(" %d", arr[cd].dscorre);
                printf("\n");
            }
        }
    }
    return 0;
}